import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { RolePlayer } from "../../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../../scene/events/PlayerEvent";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GainLevelAwardModule } from "../../../../modules/GainLevelAwardModule";
import { Cache } from "../../cache/Cache";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { ItemConfig } from "../../resource/ItemConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { IGainLevelAwardModule } from "../../../../modules/interfaces/IGainLevelAwardModule";
type int = number;
//class LevelAwardItem
    
    export  class LevelAwardItem /* flash.display.Sprite */ implements IToolTipItem
    {
        constructor()
        {
            
            this._awardArr = [];
            this.init();
            buttonMode = true;
            mouseChildren = false;
            return;
        }

        public setData(arg1: Object): void
        {
            this._type = arg1.type;
            this._level = arg1.time;
            this._awardArr = arg1.reward;
            this._awardCode = this._awardArr[0].code;
            this._awardNum = this._awardArr[0].num;
            var loc1=new BaseItem();
            var loc2=new ItemData(this._awardCode);
            loc1.itemData = loc2;
            loc1.move(2, 2);
            loc1.setSize(33, 33);
            loc1.isDragAble = false;
            loc1.isDropAble = false;
            loc1.amount = this._awardNum;
            addChild(loc1);
            if (!(this._lightMask == null) && this._lightMask.parent is LevelAwardItem) 
            {
                this.disposeLightMask();
            }
            this.addLightMask();
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.roleLevelUpdate);
            this._tipTxt.text = Language.getStringByParam(90005, this._level.toString());
            return;
        }

        /* internal  */init(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.PackItemBg);
            loc1.x = 0;
            loc1.y = 0;
            addChild(loc1);
            ToolTipsManager.register(this);
            this._tipTxt = ObjCreate.createGTextField("", -15, loc1.height + 5, 70, 20, this, GlobalStyle.textFormat1);
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            if (this._gainLevelAward == null) 
            {
                this._gainLevelAward = new GainLevelAwardModule();
            }
            if (this._gainLevelAward.isHide) 
            {
                this._gainLevelAward.show();
                this._gainLevelAward.setAwardInfo(this._level, this._awardCode, this._awardNum, this._type);
                loc1 = Cache.instance.role.entityInfo.level;
                this._gainLevelAward.roleLevelUpdate(loc1);
            }
            else 
            {
                this._gainLevelAward.hide();
            }
            return;
        }

        public onRemove(): void
        {
            if (this._gainLevelAward != null) 
            {
                this._gainLevelAward.flyLevelAwardToNavbar();
            }
            this.disposeLightMask();
            removeEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            RolePlayer.instance.removeEventListener(PlayerEvent.RoleLevelUpdate, this.roleLevelUpdate);
            return;
        }

        public disposeLightMask(): void
        {
            if (this._lightMask) 
            {
                if (this._lightMask.parent) 
                {
                    this._lightMask.parent.removeChild(this._lightMask);
                }
                this._lightMask.x = 0;
                this._lightMask.y = 0;
                this._lightMask.transform.matrix = new Object /* flash.geom.Matrix */();
                this._lightMask.stop();
                ObjectPool.disposeObject(this._lightMask);
                this._lightMask = null;
            }
            return;
        }

        public get toolTipData()
        {
            var loc1=Cache.instance.role.roleInfo.level;
            var loc2=ItemConfig.instance.getInfoByCode(this._awardCode).item.name;
            if (loc1 < this._level) 
            {
                this._toolTipData = Language.getStringByParam(90006, this._level.toString(), loc2);
            }
            else 
            {
                this._toolTipData = Language.getStringByParam(90007, loc2);
            }
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._toolTipData = arg1;
            return;
        }

        /* internal  */addLightMask(): void
        {
            var loc1=Cache.instance.role.entityInfo.level;
            if (loc1 >= this._level) 
            {
                if (this._lightMask == null) 
                {
                    this._lightMask = ObjectPool.getObject(LightMask);
                    this._lightMask.transform.matrix = new Object /* flash.geom.Matrix */();
                }
                if (!this._lightMask.parent || !(this._lightMask.parent == this)) 
                {
                    this._lightMask.gotoAndStop(1);
                    this._lightMask.x = 0;
                    this._lightMask.y = 0;
                    this._lightMask.scaleX = 1.05;
                    this._lightMask.scaleY = 1.05;
                    this._lightMask.play();
                    addChild(this._lightMask);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FlyLevelAward));
                }
            }
            if (this._gainLevelAward != null) 
            {
                this._gainLevelAward.roleLevelUpdate(loc1);
            }
            return;
        }

        /* internal  */roleLevelUpdate(arg1: PlayerEvent): void
        {
            this.addLightMask();
            return;
        }

        public flyLevelAwardToNavbar(): void
        {
            if (this._gainLevelAward != null) 
            {
                this._gainLevelAward.flyLevelAwardToNavbar();
            }
            return;
        }

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_awardCode: int;

        /* internal */ /* var */_awardNum: int;

        /* internal */ /* var */_awardArr: Array<any>;

        /* internal */ /* var */_lightMask: LightMask;

        /* internal */ /* var */_gainLevelAward: IGainLevelAwardModule;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_toolTipData;
    }
